// task_create_success_page.dart
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class TaskCreateSuccessPage extends StatefulWidget {
  final String taskId;
  final String taskCategoryStr;
  final bool againCreate;
  final VoidCallback? onBackToHome;

  const TaskCreateSuccessPage({
    super.key,
    required this.taskId,
    required this.taskCategoryStr,
    this.againCreate = false,
    this.onBackToHome,
  });

  @override
  _TaskCreateSuccessPageState createState() => _TaskCreateSuccessPageState();
}

class _TaskCreateSuccessPageState extends State<TaskCreateSuccessPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('发布任务'),
        leading: IconButton(
          icon: const Icon(Icons.arrow_back),
          onPressed: _goCustomBackAction,
        ),
      ),
      body: _buildBody(),
    );
  }

  Widget _buildBody() {
    return SingleChildScrollView(
      child: Column(
        children: [
          // 顶部内容区域
          Container(
            width: double.infinity,
            padding: EdgeInsets.only(
              top: MediaQuery.of(context).padding.top + kToolbarHeight + 20.h,
              bottom: 40.h,
            ),
            child: Column(
              children: [
                // 成功图标
                Image.asset(
                  'assets/images/renwu_fabu_tijiao_icon.png',
                  width: 80.w,
                  height: 104.h,
                  fit: BoxFit.contain,
                ),
                SizedBox(height: 24.h),

                // 成功标题
                Text(
                  '任务已提交',
                  style: TextStyle(
                    fontSize: 16.sp,
                    color: const Color(0xFF2D2D2D),
                    fontWeight: FontWeight.bold,
                  ),
                ),
                SizedBox(height: 8.h),

                // 提示信息
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: 34.w),
                  child: Text(
                    '通过审核即可上线\n"我的-发布的任务-待审核"中查看审核进度',
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      fontSize: 12.sp,
                      color: const Color(0xFFA2A2A2),
                      height: 1.5,
                    ),
                  ),
                ),
                SizedBox(height: 40.h),

                // 返回首页按钮
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: 15.w),
                  child: SizedBox(
                    width: double.infinity,
                    height: 44.h,
                    child: ElevatedButton(
                      onPressed: _customBackPress,
                      style: ElevatedButton.styleFrom(
                        backgroundColor: Theme.of(context).primaryColor,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(5.r),
                        ),
                      ),
                      child: Text(
                        '返回首页',
                        style: TextStyle(
                          fontSize: 16.sp,
                          color: Colors.white,
                        ),
                      ),
                    ),
                  ),
                ),
                SizedBox(height: 16.h),

                // 底部按钮行
                // Padding(
                //   padding: EdgeInsets.symmetric(horizontal: 15.w),
                //   child: Row(
                //     children: [
                //       // 私信客服按钮
                //       Expanded(
                //         child: SizedBox(
                //           height: 44.h,
                //           child: OutlinedButton(
                //             onPressed: _kefuPress,
                //             style: OutlinedButton.styleFrom(
                //               side: BorderSide(
                //                 color: const Color(0xFFFF4988),
                //                 width: 1.w,
                //               ),
                //               shape: RoundedRectangleBorder(
                //                 borderRadius: BorderRadius.circular(5.r),
                //               ),
                //             ),
                //             child: Text(
                //               '私信客服催审',
                //               style: TextStyle(
                //                 fontSize: 16.sp,
                //                 color: const Color(0xFFFF4988),
                //               ),
                //             ),
                //           ),
                //         ),
                //       ),
                //       SizedBox(width: 10.w),
                //
                //       // 查看任务详情按钮
                //       Expanded(
                //         child: SizedBox(
                //           height: 44.h,
                //           child: OutlinedButton(
                //             onPressed: _showPress,
                //             style: OutlinedButton.styleFrom(
                //               side: BorderSide(
                //                 color: const Color(0xFFFF4988),
                //                 width: 1.w,
                //               ),
                //               shape: RoundedRectangleBorder(
                //                 borderRadius: BorderRadius.circular(5.r),
                //               ),
                //             ),
                //             child: Text(
                //               '查看任务详情',
                //               style: TextStyle(
                //                 fontSize: 16.sp,
                //                 color: const Color(0xFFFF4988),
                //               ),
                //             ),
                //           ),
                //         ),
                //       ),
                //     ],
                //   ),
                // ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  // 自定义返回操作
  void _goCustomBackAction() {
    if (widget.againCreate) {
      // 如果是再次创建，返回到前两个页面
      Navigator.of(context).popUntil((route) => route.isFirst);
    } else {
      _customBackPress();
    }
  }

  // 返回首页
  void _customBackPress() {
    if (widget.onBackToHome != null) {
      widget.onBackToHome!();
    } else {
      // 返回到首页
      Navigator.of(context).popUntil((route) => route.isFirst);
    }
  }

  // 联系客服
  void _kefuPress() {
    // 跳转到客服聊天页面
    // RouteUtils.pushNamed(context, RoutePath.chat_customer_service);
  }

  // 查看任务详情
  void _showPress() {
    // 跳转到任务预览详情页面
    // RouteUtils.pushNamed(
    //   context,
    //   RoutePath.task_preview_detail,
    //   arguments: {
    //     'taskId': widget.taskId,
    //     'taskCategoryStr': widget.taskCategoryStr,
    //   },
    // );
  }

  @override
  void dispose() {
    super.dispose();
  }
}